/*
 * Copyright (C), 2002-2016, 苏宁易购电子商务有限公司
 * FileName: ModelClusterController.java
 * Author:   13075787
 * Date:     2016年7月11日 下午12:04:35
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.suning.sawp.web.controller.model;

import java.security.Principal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.mainpush.StoreManDto;
import com.suning.sawp.intf.model.ModelClusterVo;
import com.suning.sawp.intf.model.ModelCommClusterVo;
import com.suning.sawp.intf.model.ModelZoneInfo;
import com.suning.sawp.intf.storeman.StoreManService;
import com.suning.sawp.service.impl.model.ModelBlendServiceImpl;
import com.suning.sawp.service.impl.model.ModelCommClusterServiceImpl;
import com.suning.sawp.web.controller.DjBaseController;
import com.suning.sawp.web.exception.MyGsonView;

/**
 * 样机管理<br>
 * 簇维护
 *
 * @author 13075787
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/model/cluster")
public class ModelClusterController extends DjBaseController {

    @Autowired
    ModelBlendServiceImpl modelBlendService;

    @Autowired
    StoreManService storeManService;

    @Autowired
    ModelCommClusterServiceImpl modelCommClusterService;

    /**
     * 功能描述: <br>
     * 查询我需要维护簇的商品列表
     */
    @Deprecated
    @RequestMapping("/queryClusterList.do")
    public MyGsonView queryMyClusterComm(Principal principal, Long taskId, Integer index, Integer size) {
        MyGsonView view = new MyGsonView();
        // 工号
        String staffId = principal.getName();
        StoreManDto storeMan = storeManService.queryStoreManAttachInfo(staffId);
        if (modelBlendService.checkManInfo(storeMan)) {
            ReturnMsg<List<ModelClusterVo>> ret = modelCommClusterService.queryMaintainClusterCommList(storeMan, taskId,
                    index, size);
            view = setGsonView(ret);
        } else {
            setErrorMsg(view, ErrorCodeConstants.ERR_1009);
        }
        return view;
    }

    /**
     * 功能描述: <br>
     * 查询指定商品当前的簇商品列表
     */
    @RequestMapping("/queryTheClusters.do")
    public MyGsonView queryClusterComm(Principal principal, String commCode) {
        MyGsonView view = new MyGsonView();
        // 工号
        String staffId = principal.getName();
        StoreManDto storeMan = storeManService.queryStoreManAttachInfo(staffId);
        if (modelBlendService.checkManInfo(storeMan)) {
            ReturnMsg<List<ModelCommClusterVo>> ret = modelCommClusterService.queryModelCommClusters(storeMan,
                    commCode);
            view = setGsonView(ret);
        } else {
            setErrorMsg(view, ErrorCodeConstants.ERR_1009);
        }
        return view;
    }

    /**
     * 功能描述: <br>
     * 查询该商品的推荐簇商品（筛除掉已添加到该簇的商品）
     */
    @RequestMapping("/queryRecClusterList.do")
    public MyGsonView queryRecClusterComm(Principal principal, String commCode) {
        MyGsonView view = new MyGsonView();
        // 工号
        String staffId = principal.getName();
        StoreManDto storeMan = storeManService.queryStoreManAttachInfo(staffId);
        if (modelBlendService.checkManInfo(storeMan)) {
            ReturnMsg<List<ModelCommClusterVo>> ret = modelCommClusterService.queryRecommendModelCommClusters(storeMan,
                    commCode);
            view = setGsonView(ret);
        } else {
            setErrorMsg(view, ErrorCodeConstants.ERR_1009);
        }
        return view;
    }

    /**
     * 功能描述: <br>
     * 添加簇商品
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping("/addClusterComm.do")
    public MyGsonView addClusterComm(Principal principal, String commCode, String addCommCode) {
        MyGsonView view = new MyGsonView();
        // 工号
        String staffId = principal.getName();
        StoreManDto storeMan = storeManService.queryStoreManAttachInfo(staffId);
        if (modelBlendService.checkManInfo(storeMan)) {
            ModelZoneInfo modelZone = new ModelZoneInfo();
            modelZone.setDisCode(storeMan.getRegionCode());
            modelZone.setDisName(storeMan.getRegionName());
            modelZone.setOrgCode(storeMan.getBranchCode());
            modelZone.setOrgName(storeMan.getBranchName());
            ReturnMsg ret = modelCommClusterService.addModelCommCluster(modelZone, commCode, addCommCode);
            view = setGsonView(ret);
        } else {
            setErrorMsg(view, ErrorCodeConstants.ERR_1009);
        }
        return view;
    }

    /**
     * 功能描述: <br>
     * 删除簇中的商品
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping("/delClusterComm.do")
    public MyGsonView delClusterComm(Principal principal, String commCode, String delCommCode) {
        MyGsonView view = new MyGsonView();
        // 工号
        String staffId = principal.getName();
        StoreManDto storeMan = storeManService.queryStoreManAttachInfo(staffId);
        if (modelBlendService.checkManInfo(storeMan)) {
            ReturnMsg ret = modelCommClusterService.delModelCommCluster(storeMan, commCode, delCommCode);
            view = setGsonView(ret);
        } else {
            setErrorMsg(view, ErrorCodeConstants.ERR_1009);
        }
        return view;
    }

}
